<?php
/**
 * (exporter)
 */
namespace App\Exporter\Delivery;

use App\Models\MonthlyReport\Cost\Delivery\PacketDelivery;
use App\Util\User;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Concerns\WithMapping;

class NotFBADetailExporter extends ExcelExporter implements WithMapping
{

    protected $fileName = '非FBA发货单明细.csv';

    protected $headings = ['发货单','销售员','订单号','国家','收货人','地址','州','城市','邮编','电话','SKU',
        '产品名称','状态','数量','已确定数量','发货时间','追踪号','备注'];

    public function map($model) : array
    {
        return [
            $model->delivery_no,
            User::getUsernameById($model->delivery->seller_id ?? -1),
            $model->order_no,
            $model->delivery->receiver->country ?? '',
            $model->delivery->receiver->receiver ?? '',
            $model->delivery->receiver->address ?? '',
            $model->delivery->receiver->state ?? '',
            $model->delivery->receiver->city ?? '',
            $model->delivery->receiver->postcode ?? '',
            $model->delivery->receiver->phone ?? '',
            $model->sku->psku_code ?? '',
            $model->sku->psku_cn ?? '',
            array_key_exists($model->delivery->status ?? 1,PacketDelivery::$_status) ? PacketDelivery::$_status[$model->delivery->status ?? 1] : '',
            array_key_exists($model->delivery->logistics_status ?? 1,PacketDelivery::$_logisticsStatus) ? PacketDelivery::$_logisticsStatus[$model->delivery->logistics_status ?? 1] : '',
            $model->apply_num,
            $model->ship_num,
            $model->delivery->delivered_at ?? '',
            $model->delivery->remarks ?? '',
        ];
    }
}
